package com.example.demo5072.exception;

import com.example.demo5072.pojo.WebResult;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @author lzh
 * @date 2019/7/31 - 15:28
 */
@ControllerAdvice
public class MyExceptionHandler {
    @ExceptionHandler(MethodArgumentNotValidException.class)
    public WebResult<Void>  methodArgNotValidException(MethodArgumentNotValidException ex){
        BindingResult bindingResult = ex.getBindingResult();
        return new WebResult<Void>("参数校验异常",bindingResult.getFieldError().getDefaultMessage());
    }






}
